package org.nf.sms.util;

import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * 日期时间工具类
 *
 * @Author zqx
 * @Date 2024-03-08
 */
public class DateUtil {
    /**
     * java.sql.Timestamp 转换为 java.time.LocalDateTime
     *
     * @param timestamp
     * @return
     */
    public static LocalDateTime toLocalDateTime(Timestamp timestamp) {
        return timestamp.toLocalDateTime();
    }

    /**
     * java.time.LocalDateTime 转换为 java.sql.Timestamp
     * @param localDateTime
     * @return
     */
    public static Timestamp toTimestamp(LocalDateTime localDateTime) {
        // 获取当前系统的时区
        ZoneId zoneId = ZoneId.systemDefault();
        // 根据时区创建瞬时时间实例对象
        Instant instant = localDateTime.atZone(zoneId).toInstant();
        // 转换为java.sql.Timestamp
        return Timestamp.from(instant);
    }
}
